package lotus.blog.lotusblog.socket;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Data
public class GameMessage {
    private String type;
    private Object message;
    private static ObjectMapper objectMapper = new ObjectMapper();
    public static String sendMessage(String message) throws JsonProcessingException {
        GameMessage gm = new GameMessage();
        gm.setType("message");
        gm.setMessage(message);
        String json  = objectMapper.writeValueAsString(gm);
        return json;
    }
    public static String sendPlayers(List<Player> PlayerList) throws JsonProcessingException {
        GameMessage gm = new GameMessage();
        gm.setType("players");
        gm.setMessage(PlayerList);
        String json  = objectMapper.writeValueAsString(gm);
        return json;
    }
    public static String sendPlayer(Player Player) throws JsonProcessingException {
        GameMessage gm = new GameMessage();
        gm.setType("player");
        gm.setMessage(Player);
        String json  = objectMapper.writeValueAsString(gm);
        return json;
    }
}
